package it.acweb.pauseless.pauselessapp;

import android.os.Parcel;
import android.os.Parcelable;

public class Song implements Parcelable  {
	
	//private static int track_no;
	private String track_no;
	private String artist;
	private String title;
	private String bpm;
	private String path;
	private String[] pauses;

	//parcelable part
	public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel out, int flags) {
    	/*String [] strArr = new String[] {this.track_no,
 			   this.artist,
 			   this.title,
 			   this.bpm};
    	String [] prova = concat(strArr, pauses);
    	out.writeStringArray(prova);*/
    	out.writeString(this.track_no);
    	out.writeString(this.artist);
    	out.writeString(this.title);
    	out.writeString(this.bpm);
    	out.writeString(this.path);
    	out.writeStringArray(this.pauses);
    }
    
    public static final Parcelable.Creator<Song> CREATOR = new Parcelable.Creator<Song>() {
        public Song createFromParcel(Parcel in) {
            return new Song(in);
        }

        public Song[] newArray(int size) {
            return new Song[size];
        }
    };
    public Song(Parcel par) {
		super();
		/*String[] strArr = null;
		par.readStringArray(strArr);
		this.track_no = strArr[0];
		this.artist = strArr[1];
		this.title = strArr[2];
		this.bpm = strArr[3];
		this.pauses = Arrays.copyOfRange (strArr, 4, strArr.length - 1);*/
		this.track_no = par.readString();
		this.artist = par.readString();
		this.title = par.readString();
		this.bpm = par.readString();
		this.path = par.readString();
		par.readStringArray(this.pauses);
	}
    
    //utility
    /*private String[] concat(String[] A, String[] B) {
    	   int aLen = A.length;
    	   int bLen = B.length;
    	   String[] C= new String[aLen+bLen];
    	   System.arraycopy(A, 0, C, 0, aLen);
    	   System.arraycopy(B, 0, C, aLen, bLen);
    	   return C;
    	}*/
    //fine parcelable part
    
    public Song(String p_track_no, String p_artist, String p_title, String p_bpm, String p_path, String[] p_pauses) {
		super();
		this.track_no = p_track_no;
		this.artist = p_artist;
		this.title = p_title;
		this.bpm = p_bpm;
		this.path = p_path;
		this.pauses = p_pauses;

	}
	
	public String get_title () {
		return title;
	}

	public String get_artist () {
		return artist;
	}

	public String get_track_no () {
		return track_no;
	}

	public String get_bpm () {
		return bpm;
	}

	public String get_path () {
		return path;
	}

	public String[] get_pauses () {
		return pauses;
	}

	public String get_pauses_string () {
		String pause_string = null;
		for (int y = 0; y < pauses.length; y++) {
			if (y == 0) {
				pause_string = pauses[y];
			} else {
				pause_string = pause_string + " | " + pauses[y];
			}
		}
		return pause_string;
	}

}
